package com.asd.map.service.impl;

import com.asd.common.Result;
import com.asd.map.entity.Point_style;
import com.asd.map.mapper.Point_styleMapper;
import com.asd.map.service.IPoint_styleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @createtime 2021-09-02 9:49
 * @description
 */
@Service
public class Point_styleServiceImpl extends ServiceImpl<Point_styleMapper, Point_style> implements IPoint_styleService {

    @Autowired
    private Point_styleMapper point_styleMapper;


    @Override
    public List<Point_style> selectInformationPage(Page<Point_style> page) {

        QueryWrapper<Point_style> queryWrapper = new QueryWrapper<>();
        //  判断年龄大于20岁的，这里用的是mybatis-plus的条件构造器
//        queryWrapper.gt("age",20);
        /**
         *    加上false就不查询总记录数啦,如果不需要的话可以加上false，这样就会少一条sql语句
         *   Page<Student> page = new Page<>(current,size,false);
         */
//        Page<Information> page1 = new Page<>();
        //   queryWrapper  可以为null  不进行条件判断
        //  返回list 调用  selectPage
        IPage<Point_style> point_styleIPage = point_styleMapper.selectPage(page, queryWrapper);


//        System.out.println("总页数" + point_styleIPage.getPages());
//        System.out.println("总记录数" + point_styleIPage.getTotal());
        //getRecords()分页对象记录列表
        List<Point_style> records = point_styleIPage.getRecords();
        return records;
    }


    @Override
    public void insertBatch(List<Point_style> list) {
        for (int i = 0; i < list.size(); i++) {
            Point_style point_style = new Point_style();
            point_style = list.get(i);
            point_styleMapper.insert(point_style);
        }

    }

    @Override
    public void deleteById(String applyId, String did) {
        point_styleMapper.removeById(applyId,did);
    }

    @Override
    public List<Point_style> findByApplyId(String applyId, String did) {

        List<Point_style> point_styleList = point_styleMapper.findByApplyId(applyId, did);

        return point_styleList;
    }

    @Override
    public Result<?> updateStyleById(String id, String size, String color) {

        Result<Point_style> result = new Result<>();
        Point_style pointStyle = point_styleMapper.selectById(id);
        if (pointStyle==null){
            return Result.error("修改的样式不存在");
        }else {

            pointStyle.setSize(size);
            pointStyle.setColor(color);

            point_styleMapper.updateById(pointStyle);
            return Result.ok(pointStyle);
        }

    }


}
